<template>
  <GlobalContainer className="!bg-[#fff]" :backgroundImage="`${OSS_URL}/images/jiaofei/jiaofei_bg.png`">
    <GlobalHeader title="装修申请" :fixed="true" showBack :backgroundImage="`${OSS_URL}/images/jiaofei/jiaofei_bg.png`" />
    <div class="mb-128 rounded-20 pb-safe bg-white px-40 py-32">
      <div class="header mb-28 flex items-center">
        <image class="mr-16 size-56" src="../../static/images/jiaofei/head_icon.png" />
        <span>{{ formatRoom(accountStore.currentRoom) }}</span>
        <div class="status ml-auto" :class="statusClassMap[detail.status]">{{ statusMap[detail.status] }}</div>
      </div>

      <div class="list-c">
        <div class="item-c">
          <div class="label">申请人</div>
          <div class="value">{{ detail.realName }}</div>
        </div>
        <div class="item-c">
          <div class="label">申请人电话</div>
          <div class="value">{{ detail.phone }}</div>
        </div>
        <div class="item-c">
          <div class="label">施工单位</div>
          <div class="value">{{ detail.constructionUnit }}</div>
        </div>
        <div class="item-c">
          <div class="label">施工负责人电话</div>
          <div class="value" @tap="callPhone(detail.leaderPhone)">{{ detail.leaderPhone }}</div>
        </div>
        <div class="item-c">
          <div class="label">预计施工开始时间</div>
          <div class="value">{{ detail.constructionStartTime }}</div>
        </div>
        <div class="item-c flex flex-col items-start">
          <div class="label !w-full !text-left">施工单位资质以及施工区域照片</div>
          <div class="gap-34 mt-16 flex flex-wrap">
            <div class="size-200 bg-[#f0f0f0]" v-for="(item, index) in detail.images" :key="index">
              <image class="size-full" :src="item" />
            </div>
          </div>
        </div>
        <div class="item-c flex flex-col items-start">
          <div class="label !w-full !text-left">留言</div>
          <div class="text-28 leading-42 mt-16 break-all font-normal text-[#303133]">
            {{ detail.content }}
          </div>
        </div>
        <div class="item-c flex flex-col items-start" v-if="detail.reason">
          <div class="label !w-full !text-left">拒绝原因</div>
          <div class="text-28 leading-42 mt-16 break-all font-normal text-[#303133]">
            {{ detail.reason }}
          </div>
        </div>
      </div>
    </div>
  </GlobalContainer>
</template>

<script setup>
import { ref } from 'vue'
import { getRenovationApplyRecordDetail } from '@/common/api/report'
import { useAccountStore } from '@/store/index'
import { formatRoom } from '@/common/format'
const OSS_URL = import.meta.env.VITE_OSS_URL
const accountStore = useAccountStore()

const detail = ref({})
onLoad(options => {
  getDetail(options.id)
})

const getDetail = id => {
  uni.showLoading({
    title: '加载中...'
  })
  getRenovationApplyRecordDetail({ id: id })
    .then(res => {
      res.images = res.images ? res.images.split(',') : []
      detail.value = res
    })
    .finally(() => {
      uni.hideLoading()
    })
}
// 状态 0=待审核 1=已审核 2=已拒绝
const statusMap = {
  0: '待审核',
  1: '已通过',
  2: '已拒绝'
}
const statusClassMap = {
  0: 'status-wait',
  1: 'status-pass',
  2: 'status-fail'
}
const callPhone = phone => {
  uni.makePhoneCall({
    phoneNumber: phone
  })
}
</script>

<style lang="scss" scoped>
.list-c {
  .item-c {
    display: flex;
    font-weight: 400;
    font-size: 30rpx;
    line-height: 46rpx;
    padding-top: 24rpx;
    padding-bottom: 30rpx;
    border-bottom: 1px solid #e4e7ed88;
    .label {
      width: 240rpx;
      margin-right: 40px;
      color: #909399;
    }
    .value {
      flex: 1;
      color: #303133;
    }
  }
}

.status {
  width: 118rpx;
  height: 52rpx;
  text-align: center;
  line-height: 52rpx;
  font-weight: 400;
  font-size: 26rpx;
  color: #ffffff;
  box-shadow: inset 0rpx 8rpx 16rpx 0rpx rgba(255, 255, 255, 0.3);
  border-radius: 12rpx 0rpx 12rpx 0rpx;
}
.status-wait {
  background: linear-gradient(303deg, #ff9933 0%, #ff8000 100%);
}
.status-pass {
  background: linear-gradient(303deg, #2bd982 0%, #26bf73 100%);
}
.status-fail {
  background: linear-gradient(303deg, #ff5533 0%, #ff3333 100%);
}
</style>
